package com.sali.Tree;

/**
 * @author sali
 * @date 2025/5/5 19:13
 */
public class LeetCode_112 {

    public boolean hasPathSum(TreeNode root, int targetSum) {
        return getRes(root, targetSum);
    }

    private boolean getRes(TreeNode root, int targetSum) {
        if (root == null) {
            return false;
        }

        if (root.left == null && root.right == null) {
            return root.val == targetSum;
        }

        boolean leftJudge = getRes(root.left, targetSum - root.val);
        boolean rightJudge = getRes(root.right, targetSum - root.val);
        return leftJudge || rightJudge;
    }

}
